<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<link rel="stylesheet" type="text/css" href="../css/aui.css" />
		<style type="text/css">
			.aui-bar-tab {
				border-top: 1px solid #EEEEEE;
			}
		</style>
	</head>
	<body>
		<header class="aui-bar aui-bar-nav" id="head">
			最新消息
		</header>
		<footer class="aui-bar aui-bar-tab" id="footer">
			<div class="aui-bar-tab-item xx">
				<i class="aui-iconfont aui-icon-comment"></i>
				<div class="aui-bar-tab-label">
					消 息
				</div>
			</div>
			<div class="aui-bar-tab-item" tapmode>
				<i class="aui-iconfont aui-icon-my"></i>
				<div class="aui-bar-tab-label">
					好 友
				</div>
			</div>
			<div class="aui-bar-tab-item" tapmode>
				<i class="aui-iconfont aui-icon-gear"></i>
				<div class="aui-bar-tab-label">
					设 置
				</div>
			</div>
		</footer>
	</body>
	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/aui-tab.js" ></script>
	<script type="text/javascript" src="../script/dcc.js" ></script>
	<script type="text/javascript">
		apiready = function() {
			api.parseTapmode();
			$api.fixStatusBar($api.dom('header'));
			var head_h = $api.offset($api.dom('header')).h;
			var body_h = $api.offset($api.dom('body')).h;
			var foot_h = $api.offset($api.dom('footer')).h;
			var rect_h = body_h - head_h - foot_h;
			//返回键单击监听
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				api.toast({
					msg : '再点一哈退出应用',
					duration : 2000,
					location : 'bottom'
				});
				api.addEventListener({
					name : 'keyback'
				}, function(ret, err) {
					api.closeWidget({
						silent : true
					});
				});
				setTimeout(function() {
					api.closeWidget({});
				}, 2000)
			});
			//融云初始化
			var rong = api.require('rongCloud2');
			rong.init(function(ret, err) {
				if (ret.status == 'success') {
				    //消息监听
					jt();
					rong.connect({
						token : $api.getStorage('token')
					}, function(ret, err) {
					});
				} else {
					api.toast({
						msg : '服务器连接失败'
					});
				}
			});
			//融云消息监听器
			function jt() {
				var rong = api.require('rongCloud2');
				rong.setOnReceiveMessageListener(function(ret, err) {
					if (ret) {
						api.sendEvent({
							name : 'hhxx'
						});
						api.sendEvent({
							name : 'new_msg',
							extra : {
								msg : ret.result.message
							}
						})
					}
				})
			}
			api.openFrameGroup({
				name : 'group',
				scrollEnabled : false,
				index : 0,
				rect : {
					x : 0,
					y : head_h,
					w : 'auto',
					h : rect_h
				},
				frames : [{
					name : 'huihua',
					url : 'frame_hhxx.html',
					vScrollBarEnabled : false,
					hScrollBarEnabled : false,
				}, {
					name : 'haoyou',
					url : 'frame_friends.html',
					vScrollBarEnabled : false,
					hScrollBarEnabled : false,
				}, {
					name : 'site',
					url : 'frame_site.html',
					vScrollBarEnabled : false,
					hScrollBarEnabled : false,
				}]
			}, function(ret, err) {
			});
		}
        //底部按钮切换
		var tab = new auiTab({
			element : document.getElementById("footer")
		}, function(ret) {
			var id = ret.index - 1;
			api.setFrameGroupIndex({
				name : 'group',
				index : id
			});
			if (id == 0) {
				$api.byId('head').innerHTML = '最新消息';
			}
			if (id == 1) {
				$api.byId('head').innerHTML = '在线好友';
			}
			if (id == 2) {
				$api.byId('head').innerHTML = '我的动态';
			}
		});
	</script>
</html>
